package main

import (
	"fmt"
	"newsletter-subs/api"
	"newsletter-subs/auth"
	"newsletter-subs/pkg/config"
	"newsletter-subs/pkg/db"
	"newsletter-subs/pkg/util"
)

type User struct {
	name string
	tel  int
}

type Logger interface {
	Log(message string) error
}

type FileLogger struct{}

func (f *FileLogger) Log(message string) error {
	// Write log to a file
	fmt.Println("log file:", message)
	return nil
}

type UserManager struct {
	logger Logger
}

func NewUserManager(logger Logger) *UserManager {
	return &UserManager{
		logger: logger,
	}
}

func (u *UserManager) CreateUser(user *User) {
	// Create user
	u.logger.Log("User created")
}

// @title Newsletter Subscription API
// @version 1.0
// @description newsletter subscription.
// @termsOfService http://localhost:8080/subscription
// @Scheme http https
// @securityDefinitions.apikey  Bearer
// @in header
// @name                        Authorization
// @description                 Description for what is this security definition being used

// @contact.name Newsletter subscription API Support
// @contact.url localhost:8080/swagger/index.html
// @contact.email yangxingdy@163.com
func main() {
	util.InitLogger()
	config.Init()
	db.Init()
	// rabbitmq.Run_producer()
	// rabbitmq.Run_consumer()

	userManager := NewUserManager(&FileLogger{})
	userManager.logger.Log("logger")
	userManager.CreateUser(&User{})
	token, _ := auth.GenerateToken("yangxingdy@163.com")
	util.Logger.Println("jwt token:", token)

	api.InitServer()
}
